package com.yanzhu.service.mapper;

import com.yanzhu.service.model.GrabRedPackets;
import com.yanzhu.service.model.mix.GrabRedPacketsDetail;
import org.apache.ibatis.annotations.*;

import java.util.List;


/**
 * @Author: 方炎柱
 * @Description:
 * @Date: Created in 15:48 2018/1/29
 * @Modified:
 */
@Mapper
public interface GrabRedPacketsMapper {
    @Insert("insert into grab_red_packets(uid, vid, grab_money, grab_time) values(#{uid}, #{vid}, #{grab_money}, #{grab_time})")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = long.class)
    int insert(GrabRedPackets grabRedPackets);


    @Select("select g.grab_money, g.grab_time, g.uid, u.nickname, u.avatar" +
            " from grab_red_packets g" +
            " left join user u on u.id = g.uid" +
            " where g.vid = #{vid}" +
            " order by g.grab_time desc")
    List<GrabRedPacketsDetail> queryGrabRedPacketsDetail(@Param("vid") long vid);

    @Select("select * from grab_red_packets where uid = #{uid}" )
    GrabRedPackets queryRedPacketsByUid(@Param("uid") long uid);
}
